<template>
  <div class="container">
      <div class="regist">修改账户信息</div>
    <el-form :label-position="labelPosition" :rules="rules"  class="form" ref="formData" label-width="80px" :model="formData">
        <el-form-item label="账号" prop="username">
            <el-input v-model="formData.username" :disabled="true"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="password">
            <el-input v-model="formData.password"></el-input>
        </el-form-item>
        <el-form-item label="电话" prop="phone_num">
            <el-input v-model="formData.phone_num"></el-input>
        </el-form-item>
        <el-button type="primary" class="btn" @click="submitForm('formData')">修改</el-button>
    </el-form>
  </div>
</template>

<script>
import { post } from '../../assets/http'
export default {
  name: 'AccountManage',
  data () {
    return {
      labelPosition: 'right',
      formData: {
        store_id: '',
        username: '',
        password: '',
        phone_num: ''
      },
      rules: {
        password: [
          { required: true, message: '密码不能为空', trigger: 'blur' },
          { min: 6, max: 12, message: '长度在 6 到 12 个字符', trigger: 'blur' }
        ],
        phone_num: [
          { required: true, message: '电话不能为空', trigger: 'blur' },
          { min: 11, max: 11, message: '请检查电话号码', trigger: 'blur' }
        ]
      }
    }
  },
  async  mounted () {
    var storeId = this.$route.query.store_id
    if (storeId != null && storeId !== undefined) {
      var res = await post('store/getStoreBack', {store_id: storeId})
      if (res.flag) {
        // this.formData = {username: 1234579810, password: 1234579810, phone_num: 1234579810}
        this.formData = res.data
      } else {
        this.$message.error('请稍后再试')
      }
    }
  },
  methods: {
    async submitForm (form) {
      this.$refs[form].validate(async (valid) => {
        if (valid) {
          var res = await post('store/update', this.formData)
          if (res.flag) {
            this.$message({
              message: res.message,
              type: 'success'
            })
          } else {
            this.$message.error('网络繁忙，请稍后再试')
          }
        }
      })
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style >
.container {
    width: 30%;
    margin-left: 35%;
    margin-top: 10%;
}
.btn {
    margin-left: 200px;
}
.regist {
    color: rgb(83, 149, 236);
    font-size: 50px;
    margin-left: 150px;
    margin-top: -100px;
    margin-bottom: 50px;
}
</style>
